﻿using System;
using System.Xml;
using System.Xml.Xsl;
using Coolite.Ext.Web;
using CooliteExamples.Web.Code;

namespace CooliteExamples.Web.Pages.Control
{
		public partial class GridPanelExample : PageBase
		{
				protected void Page_Load(object sender, EventArgs e)
				{
						if (!Ext.IsAjaxRequest && !IsPostBack)
						{
								LoadPage();
						}
				}

				private void LoadPage()
				{
						BookStore.Proxy.Add(new HttpProxy()
																														{
																																DisableCaching = true,
																																Method = HttpMethod.GET,
																																Json = true,
																																Url = Core.ProcessController.Handlers.Book.GetAllBooksHandlerUrl()
																														});

						CategoryStore.Proxy.Add(new HttpProxy()
																																		{
																																				DisableCaching = true,
																																				Method = HttpMethod.GET,
																																				Json = true,
																																				Url = Core.ProcessController.Handlers.Category.GetAllCategoriesHandlerUrl()
																																		});
				}

				protected void BookStore_Submit(object sender, StoreSubmitDataEventArgs ev)
				{
						XmlNode xml = ev.Xml;
						Response.Clear();

						Response.ContentType = "application/vnd.ms-excel";
						Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls");
						XslCompiledTransform xtExcel = new XslCompiledTransform();
						xtExcel.Load(Server.MapPath("Excel.xsl"));
						xtExcel.Transform(xml, null, Response.OutputStream);

						Response.End();
				}
		}
}
